<?php

namespace App\Providers;

use Dingo\Api\Auth\Provider\Basic;
use Dingo\Api\Auth\Provider\JWT;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Request;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Schema::defaultStringLength(191);

        // 将所有的 Exception 全部交给 App\Exceptions\Handler 来处理
        app('api.exception')->register(function (\Exception $exception) {
            $request = Request::capture();

            return app('App\Exceptions\Handler')->render($request, $exception);
        });
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //注册观察者
        \App\Models\User::observe(\App\Observers\UserObserver::class);
        \App\Models\Wallet::observe(\App\Observers\WalletObserver::class);
        \App\Models\Order::observe(\App\Observers\OrderObserver::class);
        \App\Models\NewsLike::observe(\App\Observers\NewsLikeObserver::class);
        \App\Models\PostsLike::observe(\App\Observers\PostsLikeObserver::class);
        \App\Models\NewsCollects::observe(\App\Observers\NewsCollectObserver::class);
        \App\Models\PostsCollects::observe(\App\Observers\PostsCollectObserver::class);
        \App\Models\CommentsLike::observe(\App\Observers\CommentLikeObserver::class);
        \App\Models\Schedule::observe(\App\Observers\ScheduleObserver::class);
        \App\Models\Product::observe(\App\Observers\ProductObserver::class);
    }
}
